<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"  %>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.util.Enumeration, java.util.*, java.text.* "%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<%
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;
	
	Class.forName("com.mysql.jdbc.Driver"); 		//jdbc driver load
	String url = "jdbc:mysql://localhost:3306/mydb";	//connect db
	String id = "son";
	String password = "0302";

try {
	con = DriverManager.getConnection(url, id, password);
	stmt = con.createStatement(); 			//to make the Statement for SQL
	
	//String tempId = request.getParameter("memId");
	// null 값일 때의 error 방지
	String tempId = StringUtils.defaultIfEmpty(request.getParameter("memId"), "noID");
			
			
	
	
	int updateCount = 0;
	   
    StringBuilder sb = new StringBuilder();
    
    sb.append("DELETE   \n");
    
    sb.append("  FROM  mydb.members    \n");
    sb.append(" WHERE  member_id = '" + tempId + "'");
    
    // String test = "DELETE FROM mydb.members WHERE member_id ='" + tempId + "'";
    
    System.out.println("query = "+ sb.toString());
    updateCount = stmt.executeUpdate(sb.toString());
    
    if (updateCount > 0) { 
%>
	    <script type="text/javascript">
	    	alert("삭제 되었습니다.");
	    	location.href="address_list.jsp";
	    </script>	
    <% 
    } else {
    %>
	    <script type="text/javascript">
	    	alert("삭제 실패");
	    	location.href="address_list.jsp";
	    </script>	
    <% 	
    }
	%>    

<%
} catch(Exception e) {
    e.printStackTrace();
    throw e;
} finally {
    if (rs   != null)
        try { rs.close(); } catch(Exception e) {};	//JDBC 객체 연결 해제
    if (stmt != null)
        try { stmt.close(); } catch(Exception e) {};
    if (con  != null)
        try { con.close(); } catch(Exception e) {};
}
%>
</body>
</html>